package com.coke.demo.service.impl;

import com.coke.demo.mapper.UserMapper;
import com.coke.demo.model.User;
import com.coke.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 19602
 */
@Service
public class UserServiceImpl implements UserService {

    private UserMapper userMapper;

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    /**
     * 检测用户Id与密码是否正确
     *
     * @param userid:用户的id
     * @return user
     */
    @Override
    public User checkUser(int userid) {
        return userMapper.checkUser(userid);
    }

    /**
     * 用户注册
     *
     * @param user :用户注册填写的信息
     * @return true
     */
    @Override
    public Boolean insertUser(User user) {
        return userMapper.insertUser(user);
    }

    /**
     * 查询所有管理员信息
     *
     * @return List<User>
     */
    @Override
    public List<User> findAllAdmin() {
        return userMapper.findAllAdmin();
    }

    /**
     * 查询所有用户信息
     *
     * @return List<User>
     */
    @Override
    public List<User> findAllUsers() {
        return userMapper.findAllUsers();
    }

    /**
     * 查询所有学生信息
     *
     * @return List<User>
     */
    @Override
    public List<User> findAllStudents() {
        return userMapper.findAllStudents();
    }

    /**
     * 查询所有教师信息
     *
     * @return List<User>
     */
    @Override
    public List<User> findAllTeachers() {
        return userMapper.findAllTeachers();
    }

    /**
     * 根据id查询用户信息
     *
     * @param userid :用户的id
     * @return user
     */
    @Override
    public User findById(Integer userid) {
        return userMapper.findById(userid);
    }

    /**
     * 根据用户id删除用户信息
     *
     * @param userid :用户id
     * @return Boolean
     */
    @Override
    public Boolean deleteById(Integer userid) {
        return userMapper.deleteById(userid);
    }

    /**
     * 修改用户信息
     *
     * @param user :用户信息
     * @return true
     */
    @Override
    public Boolean updateUserInfo(User user) {
        return userMapper.updateUserInfo(user);
    }

    /**
     * 获取不同权限用户的数量
     *
     * @param priority 用户权限
     * @return Integer
     */
    @Override
    public Integer countUser(Integer priority) {
        return userMapper.countUser(priority);
    }

    /**
     * 根据姓名查询用户信息
     *
     * @param username :用户的姓名
     * @return user
     */
    @Override
    public ArrayList<User> queryUserByName(String username) {
        return userMapper.queryUserByName(username);
    }

}
